package com.yc.edu.web.controller.base;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public abstract class BaseController<T> {
    public static String EDIT_PAGE;
    public static String MANAGE_PAGE;
    public static String UPDATE_PAGE;
    public static String INFO_PAGE;

    public static final String MANAGE="manage";
    public static final String EDIT="edit";
    public static final String INFO="info";
    public static final String UPDATE="update";


    public BaseController() {
        try {
            ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
            //1.获取泛型真实类型
            System.out.println("=================="+pt);
            Type[] types = pt.getActualTypeArguments();
            //2.把type类型赋值给Class类型
            Class<T> clz = (Class<T>) types[0];
            //3.定义页面的静态变量
            //System.out.println(clz);
            String modelName = clz.getSimpleName().toLowerCase();
            EDIT_PAGE = modelName +"/"+EDIT;
            INFO_PAGE = modelName  +"/"+INFO;
            MANAGE_PAGE = modelName +"/" +MANAGE;
            UPDATE_PAGE = modelName  +"/"+UPDATE;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
